package br.ufrj.dcc.tp.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

	/**
	 * Classe principal do servidor. Responsável por aceitar as conexões dos clientes e repassá-las para o ServerThread.class
	 * */
	public static void main(String[] args) {
		ServerSocket server = null;
		int port = 3702;
		
		try{
			server = new ServerSocket(port);
		}catch(IOException e) {
			System.out.println("[SERVER] Could not listen on port: " + port);
			System.exit(-1);
		}		
				
		while (true) {
			//accept a connection
			try {
				System.out.println("Waiting connections ....");
				Socket socket = server.accept();
				
				(new ServerThread(socket)).start();
				
			}catch(IOException e) {
				System.out.println("[SERVER] Accepted failed on port: " + port);
				System.exit(-1);
			}
			
		}
		
	}
	
}
